﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InventorySys.controller;
using Model.Upadan;
using Model.Sadharon;
using System.Threading;
namespace InventorySys.view
{
    public partial class StockEntry : Form
    {
        private Product product;
        private ProductController productControl;
        private SizeController sizeControl;
        private ColorController colorControl;
        private List<ProductSize> allSize;
        private List<ProductColor> allColor;
        public StockEntry()
        {
            /*InitializeComponent();
            productControl = new ProductController();
            sizeControl = new SizeController();
            colorControl = new ColorController();
            allSize = new List<ProductSize>();
            allColor = new List<ProductColor>();
            product = new Product();*/
           // new Thread(new ThreadStart(StartInThread)).Start();
            StartInThread();
             
        }

       void StartInThread() 
       {
           PopulateSizeData();
           PopulateColorData();
       }

        private void SE_Btn_Add_Click(object sender, EventArgs e)
        {
            try
            {
                product.Code = SE_ProductCode.Text;
                product.ProductName = SE_ProductName.Text;
                product.IsVat = (SE_VatComBox.Text.Equals("Yes")) ? 'Y' : 'N';
                product.Price = float.Parse(SE_PurchasePrice.Text.ToString());
                product.Size = SE_Size.Text;
                product.Quantity = int.Parse(SE_Quantity.Text.ToString());
                product.Delcharge = float.Parse(SE_DelCharge.Text.ToString());
                product.Colour = SE_Colour.Text;
                product.Description = SE_Description.Text;
                product.isLive = 'L';

                if (productControl.addNewProduct(product).IsSuccess)
                {
                    MessageBox.Show("Product added successfully");
                    this.Close();
                }
                else MessageBox.Show("Failed to add New Product");
            }
            catch (Exception ee) { }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void PopulateSizeData() {
            allSize = (List<ProductSize>) sizeControl.GetAllProductSize().ResultObj;
            foreach(ProductSize _size in allSize){
               SE_Size.Items.Add( _size.Name);
            }
        }

        private void PopulateColorData() {
            allColor = (List<ProductColor>)colorControl.GetAllProductColor().ResultObj;
            foreach (ProductColor _color in allColor) {
                SE_Colour.Items.Add(_color.Name);
            }
        }

        private void sp_BtnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SE_Size_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void panelControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void StockEntry_Load(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {

        }
    }
}
